package pos.server.dac;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Alessio
 */
public class ConnectionManager
{
    private ConnectionManager()
    {
    }
    private static Connection conn;
    private static final String MY_DRIVER =
            "org.postgresql.Driver";
    private static final String MY_URL =
            "jdbc:postgresql://127.0.0.1:5432/PoS";
    private static final String LOGIN = "postgres";
    private static final String PASSWD = "postgres";
    private static String log;

    public static Connection getConnection() throws SQLException, ClassNotFoundException
    {
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        log = stackTraceElements[2].getClassName() + "." + stackTraceElements[2].getMethodName();

        if (conn == null) {
            Class.forName(MY_DRIVER);
            conn = DriverManager.getConnection(MY_URL,
                    LOGIN, PASSWD);
        } else
            conn = DriverManager.getConnection(MY_URL,
                    LOGIN, PASSWD);
        return conn;
    }
}